package com.zzw.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableTest {

	public static void main(String[] args) {
		//CallableTest callableTest = new CallableTest();
		FutureTask<Integer> task = new FutureTask<Integer>(new Callable<Integer>() {
			@Override
			public Integer call() throws Exception {
				int i = 0;
				for(;i < 100;i++){
					System.out.println(Thread.currentThread().getName() + ":ֵ" + i);
				}
				return i;
			}
		});
		
		for(int i = 0;i < 100;i++){
			System.out.println(Thread.currentThread().getName() + "ֵ:" + i);
			if(i == 20){
				System.out.println(i);
				new Thread(task,"测试1").start();
				try {
					System.out.println("result:" + task.get());
				}
				catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
}